<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/23
 * Time: 10:19
 */
namespace app\admin\model;

use think\Model;

class Smsrequestlog extends Model
{
    protected $table = 'sw_sms_request_log';
    //自动写入时间戳
    protected $autoWriteTimestamp = true;
    // 定义类型转换
    protected $type = [
        'create_time'   => 'timestamp',
    ];
    // 定义自动完成的属性
    protected $insert             = [];

    protected $field = [];
    // status属性读取器
    protected function getIsTplSmsAttr($value)
    {
        $tpl = [0 => '否', 1 => '是',];
        return $tpl[$value];
    }
    // Sign属性读取器
    protected function getSignContentAttr($value,$data)
    {
        return '【'.$data['signature'].'】'.$data['content'];
    }
    protected function getNumAttr($value,$data)
    {
        $arr = explode(',',trim($data['mobile'],','));
        return count($arr).'/'.$data['sms_size'];
    }
    // 定义关联方法
    public function client()
    {
        return $this->belongsTo('Client','client_id','id')->bind('name');
    }
    public function smstype()
    {
        return $this->belongsTo('Smstype','sms_type_id','id')->bind([
            'type'=>'name'
        ]);
    }
    public function origin()
    {
        return $this->belongsTo('Origin','sms_type_id','id')->bind([
            'origin_name'=>'name'
        ]);
    }
}